package me.uniauto.notification;

import me.uniauto.mail.MailSenderInfo;
import me.uniauto.util.AppUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created by hardy on 2018/2/24.
 */
@Component
@EnableAsync
public class AsyncNotification {

    @Value("${serverHost}")
    String mailServerHost;
    @Value("${serverPort}")
    private  String mailServerPort;
    @Value("${useSSL}")
    private  String useSSL;
    // 邮件发送者的地址
    @Value("${serverFromAddress}")
    private  String fromAddress;
    // 登陆邮件发送服务器的用户名和密码
    @Value("${serverName}")
    private  String userName;
    @Value("${serverPassword}")
    private  String password;

    @Async
    public void sendEmail(String toAddress,String subject,String content){
        System.out.println("----发送邮件结果---------"+mailServerHost);
        MailSenderInfo mailSenderInfo = new MailSenderInfo();
		mailSenderInfo.setMailServerHost(mailServerHost);
		mailSenderInfo.setMailServerPort(mailServerPort);
		mailSenderInfo.setUserName(userName);// 设置发送邮箱的用户名
		mailSenderInfo.setPassword(password);// 您的邮箱密码
		mailSenderInfo.setFromAddress(fromAddress); // 发送的邮箱地址
        mailSenderInfo.setToAddress(toAddress);
        mailSenderInfo.setValidate(true);
        mailSenderInfo.setSubject(subject);
        mailSenderInfo.setContent(content);

        boolean flag = AppUtil.INSTANCE.sendEmail(mailSenderInfo);
        System.out.println("-------"+flag);
    }

}
